<?php

/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Pesan extends CI_Controller {
    
    
    function __construct() {
        parent::__construct();       
        $this->load->library('ExCRUD');
        $this->load->model('member_model');
        
        $crud = new Excrud();
        $crud->standartCheck();    
    }

    function kontak_detil($notelp) {
        $data = array();
        $this->load->model("kontak_model");

        $notelp = strip_tags($notelp);
        $data["detil_kontak"] = $this->kontak_model->get_detil_kontak($notelp);
        
        $data['kepemilikan_port'] = $this->member_model->get_kepemilikan_port();        
        $this->load->view('header/header_member.php', $data);
        $this->load->view("pesan/kontak_detil.php", $data);
    }
    
    function kontak_add($notelp) {
        $data = array();
        $data["notelp_pemilik"] = strip_tags($notelp);
        
        $data['kepemilikan_port'] = $this->member_model->get_kepemilikan_port();        
        $this->load->view('header/header_member.php', $data);
        $this->load->view("pesan/kontak_add.php", $data);
    }

    function kontak_edit() {
        $data = array();
        $this->load->model("kontak_model");
                
        $nama_kontak = strip_tags($this->input->post("nama_kontak"));
        $notelp_kontak = strip_tags($this->input->post("notelp_kontak"));
        $group = strip_tags($this->input->post("group"));
        $keterangan = strip_tags($this->input->post("keterangan"));
        $id_kontak = strip_tags($this->input->post("id_kontak"));

        echo $this->kontak_model->update_kontak($id_kontak, $nama_kontak, $notelp_kontak, $group, $keterangan);        
    }
    
    function kontak_insert() {            
        $data = array();
        $this->load->model("kontak_model");
                
        $nama_kontak = strip_tags($this->input->post("nama_kontak"));
        $notelp_kontak = strip_tags($this->input->post("notelp_kontak"));
        $group = strip_tags($this->input->post("group"));
        $keterangan = strip_tags($this->input->post("keterangan"));        

        echo $this->kontak_model->insert_kontak($nama_kontak, $notelp_kontak, $group, $keterangan);        
    }
    
    public function pesan_masuk($interval = ""){
        $this->load->model('pesan_model');
        $data['pesan_baru'] = $this->pesan_model->get_pesan_baru();                        
        $data['pesan_masuk'] = $this->member_model->get_pesan_masuk($interval);        
        $data['kepemilikan_port'] = $this->member_model->get_kepemilikan_port();        
        $this->load->view('header/header_member.php', $data);
        $this->load->view('pesan/pesan_masuk.php', $data);
    }
    
    public function pesan_masuk_jawab($sender, $id_komplain){
        $this->load->model('pesan_model');        
        $data['pesan_terakhir'] = $this->pesan_model->get_pesan_terakhir(strip_tags($sender));
        $data['kepemilikan_port'] = $this->member_model->get_kepemilikan_port();        
        $data['id_komplain'] = strip_tags($id_komplain);
        $this->load->view('header/header_member.php', $data);
        $this->load->view('pesan/pesan_masuk_jawab.php', $data);
    }
    
    public function pesan_masuk_reply(){
        $this->load->model('pesan_model');
        $jawaban = strip_tags($this->input->post('jawaban'));
        $id_komplain = strip_tags($this->input->post('id_komplain'));
        echo $this->pesan_model->jawab_pesan($jawaban, $id_komplain);
    }

}